home *** CD-ROM | disk | FTP | other *** search
- Path: news.th-darmstadt.de!news
- From: enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner)
- Newsgroups: comp.lang.c++
- Subject: Re: A question of privacy
- Date: 20 Apr 1996 10:23:24 +0200
- Organization: Fachbereich Informatik, TH Darmstadt
- Sender: enno@kitz.inferenzsysteme.informatik.th-darmstadt.de
- Message-ID: <lt68avmhhf.fsf@kitz.inferenzsysteme.informatik.th-darmstadt.de>
- References: <3177F514.544E@cstar.ac.com>
- NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
- In-reply-to: Asgeir Olafsson's message of Fri, 19 Apr 1996 15:18:28 -0500
- X-Newsreader: Gnus v5.1
-
- In article <3177F514.544E@cstar.ac.com> Asgeir Olafsson <olafsson@cstar.ac.com> writes:
-
- Should the following work according to the ANSI C++
- standard draft?
-
- // Compiles fine under VC++ 4.0
- class A {
- private:
- A() {}
- };
-
- class B {
- public:
- A &f() { return A();} // No complaints about privacy
- };
-
- void g()
- {
- B b;
- A a = b.f();
- }
-
-
- I suspect what is happening, is that a temporary object
- is being created, so if this is legal the object could be
- deleted as soon as "a" goes out of scope?
-
- The compiler should complain about the private constructor of class 'A'.
- Anyway if you make A's ctor public, you'll return a reference to an
- object with a lifetime bounded to the member-function call. That is,
- it's not guaranteed that following copy-construction 'A a = b.f();' will
- work properly.
-
- Enno
-
-